home *** CD-ROM | disk | FTP | other *** search
- /* Z80 reference emulator
- Copyright (C) 1995 G.Woigk
-
- This file is part of Mac Spectacle and it is free software
- See application.c for details
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- based on fMSX; Copyright (C) Marat Fayzullin 1994,1995
-
- 12.Apr.95 Started work on this file KIO !
- */
-
-
- #include "kio.h"
- #include "z80.reference.h"
- #include "Z80.ppc.macros"
-
-
- // ----- Flags after logic operations -------------------------------------
- Char zlog_flags[256]; // convert A -> Z80-flags with V=parity, S, Z, and C=0
-
- // ----- The Z80 RAM ------------------------------------------------------
- Char *CORE = nil;
-
- // ----- The Z80 registers on entry and exit of Z80() ---------------------
- regs zreg;
-
-
- // ----- Dummy procs ------------------------------------------------------
- No_Output(Short A, Char N) {}
- Dont_Write(Short A, Char N) {}
-
-
- // ----- The Z80 Reference Engine ----------------------------------------------
-
- short Z80_Ref()
- { register Char c; // general purpose byte register
- register Short w; // general purpose word register
- register Short wm; // help register for macro internal use
- register pair *izp; // address ix or iy
- define_r; // define r if exact r register emulation
-
- #define loop goto nxtcmnd
-
-
- // check zreg.WUFF to see, whether an NMI or IRPT is pending:
- // also called after ei processing!
- check_wuff:
- if (zreg.WUFF)
- { if (zreg.WUFF&0x80) // NMI: 0x0066; 11 T cycles
- { do_info_nmi;
- zreg.WUFF&=0x7F;
- zreg.IFF2=zreg.IFF1;
- zreg.IFF1=disabled;
- push(pc);
- pc = 0x0066;
- more(11);
- loop;
- }
- if (zreg.IFF1==enabled) // interrupts enabled?
- { do_info_irpt;
- zreg.WUFF--; // clear interrupt request
- zreg.IFF1=zreg.IFF2=disabled; // disable iff1 & iff2
- switch (zreg.IM)
- {
- case 0: // mode 0: read instr; 1 T cycle + normal instr timing
- // if (zreg.irptcmd==RST38)
- // { push(pc);
- // pc = 0x0038;
- // more(12); // RST==11T + 1T
- // loop;
- // };
- // exit(irpt_error); // not supported instruction read in irpt ackn cycle
- case 1: // mode 1: rst 56; 13 T cycles
- push(pc);
- pc = 0x0038;
- more(13);
- loop;
- case 2: // mode2: jmp via table; 19 T cycles
- push(pc);
- w = *(Short*)&zreg.I; // read both: zreg.I & zreg.irptcmd !!!
- pc = ((Short)peek(w+1)<<8) + peek(w);
- more(19);
- loop;
- default:
- exit(irpt_error);
- };
- };
- };
-
- // ----- THE MAIN INSTRUCTION DISPATCHER --------------------------------
-
- nxtcmnd:
- if ((cc-=4)>=0) // -4 T cycles for most common instructions
- { increment_r;
- switch(n)
- {
- #include "Codes.c"
- }
- loop;
- }
- cc+=4;
- return(ok);
- }
-
-